import { createStore } from "vuex";

const store = createStore({
    state: {
        iotData: {},
        count: 0,
        avater:'',
        msg:-1,
    },
    getters: {
        getStateCount: function (state) {
            return state.iotData;
        },
        getStaateAvater : function(state) {
            return state.avater
        },
        getStateMsg : function(state){
            return state.msg
        }
    },
    mutations: {
        addCount(state, payload) {
            state.count += payload
        },
        setIOTData(state, data) {
            state.iotData = data
            console.log('setIOTData方法', state.iotData);
        },
        setIOTMsg(state,data){
            state.msg = data
            console.log('setIOTMsg',state.msg)
        },
        updateIOTTagConfig(state, data) {
            //重点，要不然页面数据不更新
            state.iotData = null
            state.iotData = data
            //console.log(state.iotData, '进入mutations');
        },
        updateIOTMsgConfig(state,data) {
            state.msg = null
            state.msg = data
            console.log("进入",state.msg)
        }
    },
    actions: {
        asyncAddStoreCount(store, payload) { // 第一个参数是vuex固定的参数，不需要手动去传递
            store.commit("addCount", payload)
        },
        asyncupdateIOTTagConfig({ commit, state }, data) {
            commit('updateIOTTagConfig', data)
        },
        asyncupdateIOTMsgConfig({ commit, state }, data) {
            commit('updateIOTMsgConfig',data)
        }
    },
    modules: {

    }
})

export default store